<?php
namespace api\modules\v1\controllers;

use api\modules\v1\models\shop\Cart;
use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpHeaderAuth;
/**
 * Default controller for the `v1` module
 */
class CartController extends DefaultController
{

    public $modelClass = 'api\modules\v1\models\HelpInfo';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }

    public function actionList() {
        if (\Yii::$app->request->isGet) {
            return (new Cart())->getCartList();
        }
    }

    //购物车相关操作
    public function actionInfo($id = 0) {
        #新增购物车
        if (\Yii::$app->request->isPost) {
            return (new Cart())->addCart();
        }

        #修改购物车
        if (\Yii::$app->request->isPut) {
            return (new Cart())->modifyCart();
        }

        #删除购物车
        if (\Yii::$app->request->isDelete) {
            return (new Cart())->deleteCart($id);
        }
    }
}
